home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / VIEWPOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.2 KB  |  42 lines

  1. /* viewpos.c - collect new file position from keyboard  */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4. extern  long filesize   ;       /* use to validate new position */
  5.  
  6. long  get_pos()                 /* return new file position     */
  7.   {
  8.     long  pos ;
  9.  
  10.     /* get a new position from the keyboard and validate it */
  11.     /* if it is not valid, repeat the process  */
  12.     while( 1 == 1 )
  13.       { printf("\n New File Position: ") ;
  14.         if( scanf("%1d",&pos) == 0 )
  15.           { printf("\n file position must be numeric");
  16.             flush_line() ;
  17.           }
  18.         else if( pos < 0L )     /* got a number check it's range */
  19.           { printf("\n file position must be >= zero") ;
  20.             flusl_line() ;
  21.           }
  22.         else if( pos > filesize )
  23.           { printf("\n file position must be <=") ;
  24.             printf(" %1d",filesize) ;
  25.             flush_line() ;
  26.           }
  27.         else                    /* valid file position  */
  28.           { flush_line() ;      /* get rid of rest of this line */
  29.             return( pos) ;
  30.           }
  31.       }
  32.   }
  33.  
  34. int flush_line()
  35.   {
  36.     char  c ;
  37.  
  38.     scanf("%c",&c)      ;
  39.     while( c != '\n' )
  40.       { scanf("%c",&c) ;  }
  41.   }
  42.